/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

import java.io.Serializable;
/**
 * Classe que representa uma conta do facebook.
 */
public class FaceBookAccount implements Serializable {
	public FaceBookAccount() {
	}
	
	public static FaceBookAccount loadFaceBookAccountByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadFaceBookAccountByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount getFaceBookAccountByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getFaceBookAccountByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadFaceBookAccountByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount getFaceBookAccountByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getFaceBookAccountByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByORMID(PersistentSession session, int ID) {
		try {
			return (FaceBookAccount) session.load(smartgrid.FaceBookAccount.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount getFaceBookAccountByORMID(PersistentSession session, int ID) {
		try {
			return (FaceBookAccount) session.get(smartgrid.FaceBookAccount.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (FaceBookAccount) session.load(smartgrid.FaceBookAccount.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount getFaceBookAccountByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (FaceBookAccount) session.get(smartgrid.FaceBookAccount.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount[] listFaceBookAccountByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listFaceBookAccountByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount[] listFaceBookAccountByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listFaceBookAccountByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount[] listFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.FaceBookAccount as FaceBookAccount");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (FaceBookAccount[]) list.toArray(new FaceBookAccount[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount[] listFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.FaceBookAccount as FaceBookAccount");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (FaceBookAccount[]) list.toArray(new FaceBookAccount[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadFaceBookAccountByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadFaceBookAccountByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy) {
		FaceBookAccount[] faceBookAccounts = listFaceBookAccountByQuery(session, condition, orderBy);
		if (faceBookAccounts != null && faceBookAccounts.length > 0)
			return faceBookAccounts[0];
		else
			return null;
	}
	
	public static FaceBookAccount loadFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		FaceBookAccount[] faceBookAccounts = listFaceBookAccountByQuery(session, condition, orderBy, lockMode);
		if (faceBookAccounts != null && faceBookAccounts.length > 0)
			return faceBookAccounts[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateFaceBookAccountByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateFaceBookAccountByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateFaceBookAccountByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateFaceBookAccountByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.FaceBookAccount as FaceBookAccount");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateFaceBookAccountByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.FaceBookAccount as FaceBookAccount");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static FaceBookAccount loadFaceBookAccountByCriteria(FaceBookAccountCriteria faceBookAccountCriteria) {
		FaceBookAccount[] faceBookAccounts = listFaceBookAccountByCriteria(faceBookAccountCriteria);
		if(faceBookAccounts == null || faceBookAccounts.length == 0) {
			return null;
		}
		return faceBookAccounts[0];
	}
	
	public static FaceBookAccount[] listFaceBookAccountByCriteria(FaceBookAccountCriteria faceBookAccountCriteria) {
		return faceBookAccountCriteria.listFaceBookAccount();
	}
	
	public static FaceBookAccount createFaceBookAccount() {
		return new smartgrid.FaceBookAccount();
	}
	
	public boolean save() {
		try {
			smartgrid.SmartgridPersistentManager.instance().saveObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean delete() {
		try {
			smartgrid.SmartgridPersistentManager.instance().deleteObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean refresh() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().refresh(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean evict() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().evict(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate() {
		try {
			smartgrid.Contract[] lContract_roles = contract_role.toArray();
			for(int i = 0; i < lContract_roles.length; i++) {
				lContract_roles[i].faceBookAccount_role.remove(this);
			}
			smartgrid.Annotation[] lAnnotationss = annotations.toArray();
			for(int i = 0; i < lAnnotationss.length; i++) {
				lAnnotationss[i].setFaceBookAccount(null);
			}
			return delete();
		}
		catch(Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate(org.orm.PersistentSession session) {
		try {
			smartgrid.Contract[] lContract_roles = contract_role.toArray();
			for(int i = 0; i < lContract_roles.length; i++) {
				lContract_roles[i].faceBookAccount_role.remove(this);
			}
			smartgrid.Annotation[] lAnnotationss = annotations.toArray();
			for(int i = 0; i < lAnnotationss.length; i++) {
				lAnnotationss[i].setFaceBookAccount(null);
			}
			try {
				session.delete(this);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			return false;
		}
	}
	
	private java.util.Set this_getSet (int key) {
		if (key == smartgrid.ORMConstants.KEY_FACEBOOKACCOUNT_CONTRACT_ROLE) {
			return ORM_contract_role;
		}
		else if (key == smartgrid.ORMConstants.KEY_FACEBOOKACCOUNT_ANNOTATIONS) {
			return ORM_annotations;
		}
		
		return null;
	}
	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {
		public java.util.Set getSet(int key) {
			return this_getSet(key);
		}
		
	};
	
	private int ID;
	
	private String UId;
	
	private String Nome;
	
	private String EMail;
	
	private boolean Enable;
	
	private java.util.Set ORM_contract_role = new java.util.HashSet();
	
	private java.util.Set ORM_annotations = new java.util.HashSet();
	
	private void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public int getORMID() {
		return getID();
	}
	
	/**
	 * Identificador da conta do facebook.
	 */
	public void setUId(String value) {
		this.UId = value;
	}
	
	/**
	 * Identificador da conta do facebook.
	 */
	public String getUId() {
		return UId;
	}
	
	/**
	 * Nome do titular da conta do facebook.
	 */
	public void setNome(String value) {
		this.Nome = value;
	}
	
	/**
	 * Nome do titular da conta do facebook.
	 */
	public String getNome() {
		return Nome;
	}
	
	/**
	 * E-mail do titular da conta do facebook.
	 */
	public void setEMail(String value) {
		this.EMail = value;
	}
	
	/**
	 * E-mail do titular da conta do facebook.
	 */
	public String getEMail() {
		return EMail;
	}
	
	public void setEnable(boolean value) {
		this.Enable = value;
	}
	
	public boolean getEnable() {
		return Enable;
	}
	
	private void setORM_Contract_role(java.util.Set value) {
		this.ORM_contract_role = value;
	}
	
	private java.util.Set getORM_Contract_role() {
		return ORM_contract_role;
	}
	
	public final smartgrid.ContractSetCollection contract_role = new smartgrid.ContractSetCollection(this, _ormAdapter, smartgrid.ORMConstants.KEY_FACEBOOKACCOUNT_CONTRACT_ROLE, smartgrid.ORMConstants.KEY_CONTRACT_FACEBOOKACCOUNT_ROLE, smartgrid.ORMConstants.KEY_MUL_MANY_TO_MANY);
	
	private void setORM_Annotations(java.util.Set value) {
		this.ORM_annotations = value;
	}
	
	private java.util.Set getORM_Annotations() {
		return ORM_annotations;
	}
	
	public final smartgrid.AnnotationSetCollection annotations = new smartgrid.AnnotationSetCollection(this, _ormAdapter, smartgrid.ORMConstants.KEY_FACEBOOKACCOUNT_ANNOTATIONS, smartgrid.ORMConstants.KEY_ANNOTATION_FACEBOOKACCOUNT, smartgrid.ORMConstants.KEY_MUL_ONE_TO_MANY);
	
	/**
	 * Retorna uma lista com os amigos do utilizador.
	 */
	public smartgrid.FaceBookAccount getFriends() {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	/**
	 * Retorna o objecto serializado no formato JSon.
	 */
	public String getJSon() {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	/**
	 * Cria o objecto serializado no formato JSon.
	 */
	public void fromJSon(String data) {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	public smartgrid.EltricStats getEletricStats(java.util.Date begin, java.util.Date end, short tipoAgregacao) {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	public smartgrid.Contract[] getContracts() {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	public String toString() {
		return String.valueOf(getID());
	}
	
}
